package com.cell.foodie.front.user.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.cell.foodie.back.user.dao.UserMapper;
import com.cell.foodie.back.user.entity.User;
import com.cell.foodie.back.utils.DemoStringUtils;

/**
 * 前台用户登录模块服务
 * @author huhu
 *
 */
@Service("userLoginService")
public class LoginServiceImpl implements LoginService {
  
  @Autowired
  UserMapper userMapper;

  @Override
  public Boolean login(User user) {
    // TODO Auto-generated method stub
    return null;
  }

  @Override
  public void register(User user) {
    
    /* 
     * 为user对象
     * 添加id
     * 添加创建时间
     */
    user.setId(DemoStringUtils.getUUID());
    user.setCreateDate(new Date());
    /*
     * 进行MD5加密
     *将账号的uuid和密码一起加密 
     */
    String pwd = user.getId() + user.getUserPwd();
    String md5Pwd = DigestUtils.md5DigestAsHex(pwd.getBytes());
    user.setUserPwd(md5Pwd);
    userMapper.add(user);
  }

}
